package com.uam.utils;


import org.apache.commons.lang3.time.DateFormatUtils;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.LineString;
import org.locationtech.jts.geom.Point;
import org.locationtech.jts.linearref.LengthIndexedLine;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 时间工具类
 */
public class DateUtils {

    public static String YYYY = "yyyy";

    public static String YYYY_MM = "yyyy-MM";

    public static String YYYY_MM_DD = "yyyy-MM-dd";

    public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";

    public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";

    /**
     * 获取当前Date型日期
     */
    public static Date getNowDate() {
        return new Date();
    }

    /**
     * 日期路径 即年/月/日 如2018/08/08
     */
    public static final String datePath() {
        Date now = new Date();
        return DateFormatUtils.format(now, "yyyy/MM/dd");
    }

    /**
     * 获取当前日期, 默认格式为yyyy-MM-dd
     *
     * @return String
     */
    public static String getDate() {
        return dateTimeNow(YYYY_MM_DD);
    }

    public static final String getTime() {
        return dateTimeNow(YYYY_MM_DD_HH_MM_SS);
    }

    public static final String dateTimeNow() {
        return dateTimeNow(YYYYMMDDHHMMSS);
    }

    public static final String dateTimeNow(final String format) {
        return parseDateToStr(format, new Date());
    }

    public static final String dateTime(final Date date) {
        return parseDateToStr(YYYY_MM_DD, date);
    }

    public static final String parseDateToStr(final String format, final Date date) {
        return new SimpleDateFormat(format).format(date);
    }

    /**
     * 返回当前时间的毫秒级别的
     *
     * @return
     * @date 2021-03-26
     * @modify heguanglong
     */
    public static Long getNewDateSs() {
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
        synchronized (format) {
            return Long.valueOf(format.format(new Date()));
        }
    }

    public static String getHHMMSS() {
        SimpleDateFormat format = new SimpleDateFormat("HH-mm-ss");
        synchronized (format) {
            return format.format(new Date());
        }
    }

    /**
     * 返回当前时间的毫秒级别的
     *
     * @param date
     * @return
     * @date 2021-03-26
     * @modify heguanglong
     */
    public static String getNewDateSs(Date date) {
        SimpleDateFormat format = new SimpleDateFormat("yyMMddHHmmss");
        synchronized (format) {
            return format.format(date);
        }
    }

    /**
     * 返回当前时间的毫秒级别的
     *
     * @param date
     * @return
     * @date 2021-03-26
     * @modify heguanglong
     */
    public static String getDateYYSs(Date date) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        synchronized (format) {
            return format.format(date);
        }
    }



    /**
     * 获取两个时间的相差的分钟秒
     *
     * @param startDate 开始时间
     * @param endDate   结束时间
     * @return
     * @author heguanglong
     * @createDate 2020年3月9日
     */
    public  static String formatTime(Date startDate, Date endDate) {
        if (startDate == null || endDate == null) {
            return null;
        }
        long millis = endDate.getTime() - startDate.getTime();
        long minutes = millis / 1000 / 60;
        long seconds = (millis / 1000) % 60;
        StringBuilder sBuilder = new StringBuilder();
        sBuilder.append(minutes).append("分").append(seconds).append("秒");
        return sBuilder.toString();
    }

}
